package com.xbongbong.paas.help;

import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.enums.ConditionEnum;
import com.xbongbong.paas.factory.SymbolFactory;
import com.xbongbong.paas.help.symbol.AbstractSymbolHandle;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.FilterConditionsPoJo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.errorcodes.BusinessRuleErrorCodeEnum;

/**
 * @author 吴峰
 * @date 2021/01/07 15:14
 */
public class SymbolHelp {

    public static boolean handleSymbol(Object target, PaasFormDataEntity paasFormDataEntity, FilterConditionsPoJo filterConditionsPoJo,
                                       FieldAttrEntity fieldAttrEntity) throws XbbException {
        AbstractSymbolHandle symbolHandle = SymbolFactory.getSymbolByFieldType(fieldAttrEntity.getFieldType());
        ConditionEnum conditionEnum = ConditionEnum.getConditionEnum(filterConditionsPoJo.getSymbol());
        switch (conditionEnum) {
            case EQUAL:
                return symbolHandle.equals(target, paasFormDataEntity, fieldAttrEntity);
            case NOEQUAL:
                return symbolHandle.noEquals(target, paasFormDataEntity, fieldAttrEntity);
            case EMPTY:
                return symbolHandle.empty(paasFormDataEntity, fieldAttrEntity);
            case NOEMPTY:
                return symbolHandle.noEmpty(paasFormDataEntity, fieldAttrEntity);
            case IN:
                return symbolHandle.in(target, paasFormDataEntity, fieldAttrEntity);
            case NOIN:
                return symbolHandle.noIn(target, paasFormDataEntity, fieldAttrEntity);
            case LIKE:
                return symbolHandle.like(target, paasFormDataEntity, fieldAttrEntity);
            case NOLIKE:
                return symbolHandle.noLike(target, paasFormDataEntity, fieldAttrEntity);
            case INCLUDE:
                return symbolHandle.include(target, paasFormDataEntity, fieldAttrEntity);
            case ALLINCLUDE:
                return symbolHandle.allInclude(target, paasFormDataEntity, fieldAttrEntity);
            case GREATEREQUAL:
                return symbolHandle.greaterEqual(target, paasFormDataEntity, fieldAttrEntity);
            case LESSEQUAL:
                return symbolHandle.lessEqual(target, paasFormDataEntity, fieldAttrEntity);
            case GREATERTHAN:
                return symbolHandle.greaterThan(target, paasFormDataEntity, fieldAttrEntity);
            case LESSTHAN:
                return symbolHandle.lessThan(target, paasFormDataEntity, fieldAttrEntity);
            case RANGE:
                return symbolHandle.range(target, paasFormDataEntity, fieldAttrEntity);
            case DYNAMIC:
                return symbolHandle.dynamic(target, paasFormDataEntity, fieldAttrEntity);
            default:
                throw new XbbException(BusinessRuleErrorCodeEnum.API_ERROR_261026);
        }
    }
}
